<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Description of counter_model
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Counter_model extends CI_Model {

    //put your code here

    function __construct() {
        parent::__construct();
        log_message('debug', 'Model Initialized');
    }

    function count_listing($status=Null) {
        $this->db->where('status', $status);
        $query = $this->db->get('listing_master');
        if ($query->num_rows() > 0) {
            return $query->num_rows();
        } else {
            return 0;
        }
    }

    function count_photos($status=Null) {
        $this->db->where('status', $status);
        $query = $this->db->get('photos');
        if ($query->num_rows() > 0) {
            return $query->num_rows();
        } else {
            return 0;
        }
    }

    function count_logos($status=Null) {
        $this->db->where('logo <>', $status);
        $query = $this->db->get('listing_master');
        if ($query->num_rows() > 0) {
            return $query->num_rows();
        } else {
            return 0;
        }
    }

    function count_banners() {
        $this->db->where('banner <>', 'nobanner.gif');
        $query = $this->db->get('listing_master');
        if ($query->num_rows() > 0) {
            return $query->num_rows();
        } else {
            return 0;
        }
    }

    function count_videos($status=Null) {
        $this->db->where('status', $status);
        $query = $this->db->get('videos');
        if ($query->num_rows() > 0) {
            return $query->num_rows();
        } else {
            return 0;
        }
    }

    function count_categories($status=Null) {
        $this->db->where('status', $status);
        $query = $this->db->get('keyword_category');
        if ($query->num_rows() > 0) {
            return $query->num_rows();
        } else {
            return 0;
        }
    }

    function count_keywords($status=Null) {
        $this->db->where('status', $status);
        $query = $this->db->get('keyword_master');
        if ($query->num_rows() > 0) {
            return $query->num_rows();
        } else {
            return 0;
        }
    }

    //joy
    function count_record($tableName=NULL, $fieldName=NULL, $fieldValue=NULL) {

        $sql = "Select count(*)as total from $tableName where $fieldName=$fieldValue ";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

    function count_record_member($tableName=NULL, $fieldName=NULL) {

        $sql = "Select count(*)as total from $tableName";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

    //--subha
    function count_member() {
        $sql = "Select count(*)as total from member_master where status <>98";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

    //--subha
    function count_incorrect_report() {
        $sql = "Select count(*)as total from report_incorrect_master where status =51";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

    //--subha
    function count_enquiry() {
        $sql = "Select count(*)as total from enquiry_master";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

    //--subha
    function count_review() {
        $sql = "Select count(*)as total from review_master";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

    //--Member Area Counter detail

    function listing_total_view($id=Null) {
        $sql = "Select viewed as total from listing_master where id=$id";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

    function count_listing_email_enquiry($id=Null) {
        $sql = "Select count(*)as total from enquiry_master where mode='EMAIL' and listing_id=$id";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

    function count_listing_SMS_enquiry($id=Null) {
        $sql = "Select count(*)as total from enquiry_master where mode='SMS' and listing_id=$id";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

    function listing_counter_by_id($id) {
        $sql = "Select count(*) as total from listing_master where mem_id=$id";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

}

?>
